from AI接口.base import APIClient


class SiliconFlowClient(APIClient):
    def __init__(self, api_key):
        super().__init__(base_url="https://api.siliconflow.cn/v1", api_key=api_key)

    def chat(self, messages, model="Qwen/Qwen2.5-7B-Instruct", stream=False, **kwargs):
        payload = {
            "model": model,
            "messages": messages,
            "stream": stream,
            **kwargs
        }
        response = self.request("POST", "chat/completions", payload=payload)
        return response.json()


if __name__ == '__main__':
    siliconflow_client = SiliconFlowClient(api_key="<SiliconFlow API Key>")
    response = siliconflow_client.chat(
        messages=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": "https://sf-maas-uat-prod.oss-cn-shanghai.aliyuncs.com/dog.png",
                            "detail": "auto"
                        }
                    }
                ]
            }
        ],
        max_tokens=512,
        temperature=0.7,
        top_p=0.7,
        top_k=50,
        frequency_penalty=0.5,
        n=1,
        response_format={"type": "text"}
    )
    print(response)
